package com.hqq.proxy;

import com.hqq.annotation.Aspect;
import com.hqq.annotation.Controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Method;

/**
 * ControllerAspect
 * 拦截Controller的所有方法
 * Created by heqianqian on 2017/7/21.
 */
@Aspect(Controller.class)
public class ControllerAspect extends AspectProxy {

    private static final Logger LOGGER = LoggerFactory.getLogger(ControllerAspect.class);

    private long startTime;

    @Override
    protected void before(Class<?> targetClass, Method targetMethod, Object[] methodParams) {
        //实现日志记录功能
        LOGGER.debug("-----begin-----");
        LOGGER.debug("controller:" + targetClass.getName() + " method:" + targetMethod.getName());
        startTime = System.currentTimeMillis();
    }

    @Override
    protected void after(Class<?> targetClass, Method targetMethod, Object[] methodParams, Object proxyResult) {
        LOGGER.debug("cost time:" + (System.currentTimeMillis() - startTime));
        LOGGER.debug("-----END-----");
    }
}
